from rest_framework.viewsets import GenericViewSet

from apps.models import HouseKeeping
from apps.serializers.ListHousekeeping import ListThingSerializer
from apps.utils.common_response import APIResponse


class IncreaseRecommend(GenericViewSet):
    def list(self,request):
        try:
            id=request.GET.get('id',-1)
            thing=HouseKeeping.objects.filter(id=id).first()
            thing.recommend_count+=1
            thing.save()
        except HouseKeeping.DoesNotExist:
            return APIResponse(code=1, msg='对象不存在')
        serializer = ListThingSerializer(thing)
        return APIResponse(code=0, msg='操作成功', data=serializer.data)